<template>
	<div class="page">
		<c-header>
			<view class="header" slot="header">
				<view class="title">文件预览</view> 
			</view>
		</c-header>
		<web-view class="webview" :src="url" :update-title="false"></web-view>
	</div>
</template>

<script>
	import {
		HTTP_REQUEST_URL,HOST
	} from '@/config.js'
	import {
		jsonToQuery
	} from '@/common/util.js'
	import {
		downloadFile
	} from '@/common/promise.js'
	export default {
		name: '',
		data() {
			return {
				isLogin: false,
				path:'',
				url: '',
				params: {},
				userInfo: uni.getStorageSync('userInfo'), 
				project_id:'',
				procure_id:'',
				task_id:'',
				type:'',
				name:'',
				module:'',
				user_id:''
			}
		},
		async onLoad(params) {  
			console.log('params',params)
			this.type=params.type;
			this.name=params.name;
			this.module=params.module;
			// 
			let fileUrl='';
			if(this.module=='caigou'){ 
				console.log('采购管理')
				this.procure_id=params.procure_id;
				this.user_id=params.user_id;
				fileUrl = encodeURIComponent(`${HOST}/api/procurefile/viewfile?procure_id=${this.procure_id}&type=${this.type}&name=${this.name}&user_id=${this.user_id}`) // encodeURIComponent 函数可把字符串作为 URI 组件进行编码。       			
				if(this.$checkFileType(this.name)==3){
					// pdf 类型 
					if(plus.os.name === 'Android') {
						this.url=`/hybrid/html/web/viewer.html?file=${fileUrl}`;
					}else {
						// ios，直接访问pdf所在路径
						this.url = encodeURIComponent(fileUrl);
					}			
				}else{  
					this.url=`${HOST}/api/procurefile/viewfile?procure_id=${this.procure_id}&type=${this.type}&name=${this.name}&user_id=${this.user_id}`; 
									 // /api/procurefile/viewfile?name=智慧农林软件使用说明.docx&procure_id=6&user_id=1&type=6
									 
					console.log('path',this.url)
				} 			
				
			}else if(this.module=='keyan'){
				// https://xmjz.pher.cn/api/scifile/viewfile?user_id=25&name=测试22.doc 
				this.user_id=params.user_id;
				fileUrl = encodeURIComponent(`${HOST}/api/scifile/viewfile?name=${this.name}&user_id=${this.user_id}&type=1`) // encodeURIComponent 函数可把字符串作为 URI 组件进行编码。       			
				if(this.$checkFileType(this.name)==3){
					// pdf 类型 
					if(plus.os.name === 'Android') {
						this.url=`/hybrid/html/web/viewer.html?file=${fileUrl}`;
					}else {
						// ios，直接访问pdf所在路径
						this.url = encodeURIComponent(fileUrl);
					}			
				}else{  
					this.url=`${HOST}/api/scifile/viewfile?name=${this.name}&user_id=${this.user_id}`; 
									 // /api/procurefile/viewfile?name=智慧农林软件使用说明.docx&procure_id=6&user_id=1&type=6
									 
					console.log('path',this.url)
				} 		
			}else if(this.module=='hetong'){  
				fileUrl = encodeURIComponent(`${HOST}/api/file/viewfile?file_path=${this.name}`) // encodeURIComponent 函数可把字符串作为 URI 组件进行编码。
				
				if(this.type==3){
					console.log('hetong')
					// pdf 类型 
					if(plus.os.name === 'Android') {
						this.url=`/hybrid/html/web/viewer.html?file=${fileUrl}`;
					}else {
						// ios，直接访问pdf所在路径
						this.url = encodeURIComponent(fileUrl);
					}			
				}else{  
					this.url=`${HOST}/api/file/viewfile?file_path=${this.name}`; 
				} 
				
			}else{				
				this.task_id=params.task_id;
				this.project_id=params.project_id;
				fileUrl = encodeURIComponent(`${HOST}/api/file/viewfile?task_id=${this.task_id}&project_id=${this.project_id}&name=${this.name}`) // encodeURIComponent 函数可把字符串作为 URI 组件进行编码。
				
				if(this.type==3){
					// pdf 类型 
					if(plus.os.name === 'Android') {
						this.url=`/hybrid/html/web/viewer.html?file=${fileUrl}`;
					}else {
						// ios，直接访问pdf所在路径
						this.url = encodeURIComponent(fileUrl);
					}			
				}else{   
					this.url=`${HOST}/api/file/viewfile?task_id=${this.task_id}&project_id=${this.project_id}&name=${this.name}`; 
				} 
			} 
			
			
			console.log(this.url)
		},
		async onShow() {

		},
		onReady() {
			 
		},
		methods: {
			
		},
		computed: {

		},
		components: {

		},
	}
</script>

<style lang="less">
	.webview {
		width: 100%;
		height: 100%;
	}
</style>
